package com.hgkj.cloud.base.scheme.table;

import com.hgkj.cloud.base.scheme.ClsAnswerRequest;
import com.hgkj.cloud.base.scheme.ClsAnswerResult;
import com.hgkj.cloud.base.scheme.ClsScore;

import java.math.BigDecimal;
import java.util.*;

/**
 * 五、六、明尼苏达多相人格测验(399题)（Mmpi399）,明尼苏达多相人格测验(566题)（Mmpi566）
 */
public class Table5 extends AbstractTable implements TableCalculate{
    String code = "Mmpi399";

    @Override
    public String getCode() {
        return code;
    }

    @Override
    public ClsAnswerResult calc(ClsAnswerRequest answer) {
        return GetMmpiFactorScore(answer);
    }

    @Override
    public String[] report(Map map) {
        return GetMmpiReport(map);
    }

    // 五、六、明尼苏达多相人格测验(399题)（Mmpi399）,明尼苏达多相人格测验(566题)（Mmpi566）
    private static ClsAnswerResult GetMmpiFactorScore(ClsAnswerRequest answer) {
        ClsAnswerResult result = new ClsAnswerResult();
        result.setMessage("");
        result.setType(answer.getType());
        result.setUuid(answer.getUuid());

        // 只使用性别常模
        int vMode = 0;

        int intSex = answer.getSex();

        try {
            // 1弃权题数，2谎分、3诈分、4校正分、5疑病、6抑郁、7癔症、8心理变态、9男性化--女性化、10偏执、11精神衰弱、12精神分裂、13轻躁症、14社会内向、
            // (15外显性焦虑、16依赖性、17支配性、18社会责任、19控制力，只有在566时才有)、20不一致性
            // 用户答案
            int intI;
            String[] strAnswer_c = answer.getAnswer().split(g_sChar);
            if (strAnswer_c.length > 1) {
                for (intI = 1; intI < strAnswer_c.length; intI++) {
                    strAnswer_c[intI] = strAnswer_c[intI].trim();
                }
            }

            String[] sAnswer = strAnswer_c[0].toString().split(g_nChar);

            int i, j, k;
            int int399or566 = 0;

            if (sAnswer.length == 399 || sAnswer.length == 566) {

            } else {
                result.setMessage("答案数量不符！");
                return result;
            }

            // 共分2组，第一组0,1,0，第二组1,0,0
            String[][] strNumberA = { { "", "15,30,45,60,75,90,105,120,135,150,165,195,225,255,285",
                    "17,20,54,65,75,83,112,113,115,164,169,177,185,196,199,220,257,258,272,276",
                    "30,39,71,89,124,129,134,138,142,148,160,170,171,180,183,217,234,267,272,296,316,322,368,370,372,373,375,386,394",
                    "2,3,7,9,18,51,55,63,68,103,130,153,155,163,175,188,190,192,230,243,274,281",
                    "2,8,9,18,30,36,39,46,51,57,58,64,80,88,89,95,98,107,122,131,145,152,153,154,155,160,178,191,207,208,233,241,242,248,263,270,271,272,285,296",
                    "2,3,6,7,8,9,12,26,30,51,55,71,89,93,103,107,109,124,128,129,136,137,141,147,153,160,162,163,170,172,174,175,180,188,190,192,201,213,230,234,243,265,267,274,279,289,292",
                    "8,20,37,82,91,96,107,134,137,141,155,170,171,173,180,183,201,231,235,237,248,267,287,289,294,296",
                    "", "93,107,109,111,117,124,268,281,294,310,316,319,327,347,348", "3,8,36,122,152,164,178,329,353",
                    "17,65,103,119,177,178,187,192,196,220,276,281,302,306,309,310,318,322,330",
                    "101,105,111,119,120,148,166,171,180,267,289",
                    "25,33,57,91,99,119,126,143,193,208,229,231,254,262,281,296,309,353,359,367,371,374,377,380,381,382,383,384,387,388,390,391,392,395,396,397",
                    "7,18,107,163,190,230,242,264,287,367,407,520,528", "9,79,107,163,170,193,264,411",
                    "32,61,82,86,94,186,223,224,240,249,250,267,268,304,343,356,419,483,547,558,562",
                    "6,28,30,33,56,116,118,157,175,181,223,224,260,304,388,419,434,437,468,471,472,529,553,558",
                    "58,80,92,96,111,167,174,220,242,249,250,291,313,360,439,444,449,483,488,489,527,548" },
                    { "", "",
                            "14,27,31,34,35,40,42,48,49,50,53,56,66,85,121,123,139,146,151,156,168,184,197,200,202,205,206,209,210,211,215,218,227,245,246,247,252,256,269,275,286,288,291,293",
                            "96", "23,29,43,62,72,108,114,125,161,189,273",
                            "5,32,41,43,52,67,86,104,130,138,142,158,159,182,189,193,236,259,288,290",
                            "10,23,32,43,44,47,76,114,179,186,189,238,253",
                            "16,21,24,32,33,35,38,42,61,67,84,94,102,106,110,118,127,215,216,224,239,244,245,284", "",
                            "16,24,27,35,110,121,123,127,151,157,158,202,275,284,291,293,299,305,314,317,326,338,341,364,365",
                            "10,15,22,32,41,61,76,86,94,102,106,142,159,182,189,217,238,266,301,304,321,336,337,340,342,343,344,346,349,351,352,356,357,358,359,360,361,362,366",
                            "15,22,40,41,47,52,76,97,104,121,156,157,159,168,179,182,194,202,210,212,238,241,251,259,266,273,282,291,297,301,303,307,308,311,312,315,320,323,324,325,328,331,332,333,334,335,339,341,345,349,350,352,354,355,356,360,363,364,366",
                            "11,13,21,22,59,64,73,97,100,109,127,134,143,156,157,167,181,194,212,222,226,228,232,233,238,240,250,251,263,266,268,271,277,279,298",
                            "32,67,82,111,117,124,138,147,171,172,180,201,236,267,278,292,304,316,321,332,336,342,357,369,370,373,376,378,379,385,389,393,398,399",
                            "13,14,23,31,32,43,67,86,125,142,158,186,191,217,238,241,263,301,317,321,322,335,337,340,352,361,372,398,418,424,431,439,442,499,506,530,555",
                            "19,21,24,41,63,67,70,82,86,98,100,138,141,158,165,180,189,201,212,236,239,259,267,304,305,321,337,338,343,357,361,362,370,372,373,393,398,399,408,440,443,461,487,488,489,509,521,531,554",
                            "64,229,255,270,406,432,523", "58,111,173,221,294,412,501,552",
                            "6,20,30,56,67,105,116,134,145,162,169,181,225,236,238,285,296,319,337,376,379,381,418,447,460,461,529,555" } };
            int[][] intScoreA = { { 0, 1, 0 }, { 1, 0, 0 } };
            String[] strSubA;

            // 1弃权题数，独列出(所有题目，选3+1)
            // 9“男性化-女性化”独列出
            String[] strMaleA = {
                    "1,19,26,28,79,80,81,89,99,112,115,116,117,120,133,144,179,198,213,314,219,221,223,229,249,254,260,262,264,280,283,300",
                    "4,25,69,70,74,77,78,87,92,126,132,134,140,149,179,187,203,204,217,226,231,239,261,278,282,295,297,299" };
            String[] strFemaleA = {
                    "1,19,26,28,69,79,80,81,89,99,112,115,116,117,120,144,176,179,198,213,214,219,221,223,229,231,249,254,260,262,264,280,283,297,300",
                    "4,25,70,74,77,78,87,92,126,132,133,134,140,149,187,203,204,217,226,239,261,278,282,295,299" };

            // 标准分的计分组(公式中的各项内容)
            float[][] sngStandardA;

            // 按“标准分”得到“诊断结果”
            // String[] vAppraiseA = new String[20];
            String[] vAppraiseA = { "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" };
            // 按“标准分”得到“指导意见”，其中的一个“总评”借用“不一致性”的
            // String[] vDoctorIdeaA = new String[20];
            String[] vDoctorIdeaA = { "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" };

            float[][] vFactorA = new float[20][2]; // 实际为20个因子
            for (i = 0; i < vFactorA.length; i++) {
                for (j = 0; j < vFactorA[i].length; j++) {
                    vFactorA[i][j] = 0;
                }
            }

            if (sAnswer.length == 399) {
                /*
                 * 调整已有数据的数组长度示例代码 int[] oldArr = { 1, 2, 3 }; int[] newArr = new
                 * int[oldArr.length + 2]; //arraycopy(被复制的数组, 从第几个元素开始复制, 要复制到的数组, 从第几个元素开始粘贴,
                 * 一共需要复制的元素个数); System.arraycopy(oldArr, 0, newArr, 0, oldArr.length); oldArr =
                 * newArr; System.out.println(oldArr[1]);
                 */

                int399or566 = 1;
                String[] newArr = new String[sAnswer.length + 167];
                // arraycopy(被复制的数组, 从第几个元素开始复制, 要复制到的数组, 从第几个元素开始粘贴,
                // 一共需要复制的元素个数);
                System.arraycopy(sAnswer, 0, newArr, 0, sAnswer.length);
                sAnswer = newArr;
                for (i = 0; i < 167; i++) {
                    sAnswer[i + 399] = "1";
                }
            } else {
                int399or566 = 2;
            }

            // “原始分”
            // 17个因子计分
            for (i = 0; i < strNumberA.length; i++) {
                for (j = 0; j < strNumberA[i].length; j++) {
                    if (strNumberA[i][j].length() > 0) {
                        strSubA = strNumberA[i][j].split(",");
                        for (k = 0; k < strSubA.length; k++) {
                            vFactorA[j][0] += intScoreA[i][Integer.valueOf(sAnswer[Integer.valueOf(strSubA[k]) - 1])
                                    - 1];
                        }
                    }
                }
            }

            // 1“弃权题数”
            for (i = 0; i < sAnswer.length; i++) {
                vFactorA[0][0] += (Integer.valueOf(sAnswer[i]) >= 3 ? 1 : 0);
            }

            // 9“男性化-女性化”
            String[] strTemp;
            strTemp = (intSex == 1 ? strMaleA : strFemaleA);
            for (i = 0; i < strTemp.length; i++) {
                strSubA = strTemp[i].split(",");
                for (j = 0; j < strSubA.length; j++) {
                    vFactorA[8][0] += intScoreA[i][Integer.valueOf(sAnswer[Integer.valueOf(strSubA[j]) - 1]) - 1];
                }
            }

            // 20“不一致性”独列出
            String[] strInconsistentlyA = { "8,13,15,16,20,21,22,23,24,32,33,35,37,38,305,317",
                    "318,290,314,315,310,308,326,288,333,328,323,331,302,311,366,362" };
            String[] strTempA;
            strSubA = strInconsistentlyA[0].split(",");
            strTempA = strInconsistentlyA[1].split(",");
            for (i = 0; i < strSubA.length; i++) {
                // if (sAnswer[Integer.valueOf(strSubA[i])-1] ==
                // sAnswer[Integer.valueOf(strTempA[i])-1])
                if (sAnswer[Integer.valueOf(strSubA[i]) - 1].equals(sAnswer[Integer.valueOf(strTempA[i]) - 1])) {
                    vFactorA[19][0] += 1;
                }
            }

            // “标准分”(公式：Standard(i) = 50 + 10 * (Original(i) – arrMinus(i)) /
            // arrDivisor(i))
            boolean blReverse = intSex == 1 ? false : true; // 有反向的计分

            switch (vMode) {
                case 0: // 性别组常模
                    if (intSex == 1) { // 男
                        float[][] sngValueA = {
                                { 5.7f, 13.68f, 13f, 8.78f, 26.16f, 22.07f, 18.98f, 27.56f, 12.84f, 17.86f, 23.01f, 18.48f,
                                        34.51f, 18.86f, 26.09f, 15.39f, 20.54f, 25.26f },
                                { 2.52f, 6.86f, 4.66f, 4.75f, 4.97f, 5.36f, 4.36f, 4.04f, 3.92f, 7.93f, 10.15f, 5.26f,
                                        6.88f, 7.45f, 8.05f, 3.12f, 4.13f, 3.76f } };
                        sngStandardA = sngValueA;
                    } else {
                        float[][] sngValueA = {
                                { 5.64f, 11.69f, 12.25f, 9.83f, 28.4f, 22.82f, 18.29f, 31.83f, 12.62f, 18.77f, 22.5f,
                                        16.64f, 37.27f, 20.43f, 29.12f, 15.1f, 21.78f, 24.86f },
                                { 2.48f, 5.02f, 4.26f, 4.98f, 5.04f, 5.54f, 4.45f, 3.86f, 3.93f, 7.82f, 9.57f, 5.16f, 6.71f,
                                        7.35f, 7.61f, 2.76f, 3.13f, 3.7f } };
                        sngStandardA = sngValueA;
                    }
                    break;
                case 1: // 性别和年龄组常模，年龄：16-25岁
                    if (intSex == 1) {
                        float[][] sngValueA = {
                                { 5.31f, 12.63f, 12.29f, 8.34f, 25.79f, 21.5f, 19.05f, 27.81f, 12.98f, 19.31f, 23.83f,
                                        19.56f, 34.84f, 19.74f, 27.82f, 15.07f, 20.4f, 25.27f },
                                { 2.44f, 5.36f, 4.38f, 4.3f, 5.02f, 5.04f, 4.44f, 4.25f, 3.93f, 7.74f, 9.15f, 4.98f, 7.19f,
                                        7.58f, 7.58f, 2.89f, 3.56f, 3.89f } };
                        sngStandardA = sngValueA;
                    } else {
                        float[][] sngValueA = {
                                { 5.59f, 11.89f, 11.66f, 9.47f, 28f, 22.2f, 18.43f, 31.81f, 12.89f, 19.81f, 23.96f, 17.49f,
                                        37.5f, 20.83f, 30.42f, 14.76f, 21.27f, 24.65f },
                                { 2.48f, 5.03f, 4.05f, 4.71f, 5.09f, 5.43f, 4.31f, 4.03f, 4.02f, 7.6f, 9.26f, 4.96f, 6.95f,
                                        7.23f, 7.47f, 2.93f, 3.42f, 4.07f } };
                        sngStandardA = sngValueA;
                    }
                    break;
                case 2: // 性别和年龄组常模，年龄：26-35岁
                    if (intSex == 1) {
                        float[][] sngValueA = {
                                { 5.99f, 16.49f, 13.39f, 9.19f, 26.34f, 22.34f, 19.29f, 27.4f, 13.05f, 17.68f, 24.75f,
                                        18.61f, 34.57f, 19.04f, 25.27f, 14.99f, 19.42f, 25.24f },
                                { 2.51f, 8.72f, 4.63f, 4.89f, 4.64f, 5.28f, 3.99f, 3.82f, 3.95f, 7.6f, 10.98f, 5.25f, 6.35f,
                                        6.97f, 7.87f, 3.17f, 4.71f, 3.82f } };
                        sngStandardA = sngValueA;
                    } else {
                        float[][] sngValueA = {
                                { 5.57f, 11.44f, 12.48f, 10.18f, 28.82f, 23.2f, 18.04f, 32.13f, 12.28f, 18.03f, 21.46f,
                                        15.74f, 37.69f, 20.2f, 28.27f, 15.2f, 22.24f, 25.05f },
                                { 2.5f, 4.89f, 4.52f, 5.39f, 5.24f, 5.78f, 4.69f, 4.13f, 4.01f, 8.01f, 9.83f, 5.06f, 6.92f,
                                        7.66f, 7.98f, 2.88f, 3.08f, 3.86f } };
                        sngStandardA = sngValueA;
                    }
                    break;
                case 3: // 性别和年龄组常模，年龄：36-45岁
                    if (intSex == 1) {
                        float[][] sngValueA = {
                                { 5.75f, 12.31f, 13.44f, 8.57f, 26.53f, 22.14f, 19.11f, 27.4f, 12.6f, 16.33f, 19.95f, 16.8f,
                                        34.22f, 17.58f, 24.92f, 16.27f, 22.04f, 25.69f },
                                { 2.63f, 5.68f, 5.2f, 5.16f, 5.2f, 5.74f, 4.51f, 3.83f, 3.94f, 8.31f, 10.39f, 5.56f, 7.17f,
                                        7.56f, 8.63f, 3.47f, 3.8f, 3.3f } };
                        sngStandardA = sngValueA;
                    } else {
                        float[][] sngValueA = {
                                { 6.07f, 10.94f, 13.45f, 10.89f, 29.6f, 24.61f, 17.95f, 32.57f, 12.28f, 16.58f, 19.45f,
                                        14.36f, 36.69f, 19.76f, 27.05f, 15.82f, 22.78f, 24.76f },
                                { 2.56f, 4.95f, 4.2f, 5.23f, 5.42f, 6.03f, 4.91f, 3.93f, 3.78f, 8.01f, 9.46f, 4.82f, 6.94f,
                                        7.78f, 8f, 2.72f, 3.28f, 3.71f } };
                        sngStandardA = sngValueA;
                    }
                    break;
                case 4: // 性别和年龄组常模，年龄：46-55岁
                    if (intSex == 1) {
                        float[][] sngValueA = {
                                { 6.5f, 11.95f, 14.39f, 9.83f, 26.71f, 23.71f, 17.57f, 27.13f, 11.97f, 14.26f, 18.83f,
                                        15.88f, 33.3f, 16.26f, 22.75f, 16.77f, 22.44f, 24.55f },
                                { 2.41f, 5.44f, 4.54f, 5.28f, 5.27f, 5.97f, 4.47f, 3.96f, 3.59f, 7.45f, 9.18f, 4.32f, 6.4f,
                                        7.34f, 7.93f, 2.64f, 3.64f, 3.55f } };
                        sngStandardA = sngValueA;
                    } else {
                        float[][] sngValueA = {
                                { 5.2f, 12.92f, 12.43f, 8.23f, 26.06f, 21.08f, 18.9f, 28.4f, 12.71f, 19.17f, 23.27f, 19.45f,
                                        34.45f, 19.34f, 27.29f, 15.15f, 20.08f, 25.1f },
                                { 2.39f, 5.76f, 4.54f, 3.97f, 4.84f, 4.57f, 4.51f, 4.52f, 3.91f, 7.64f, 9.63f, 5.79f, 6.71f,
                                        6.61f, 6.45f, 2.76f, 3.72f, 4.42f } };
                        sngStandardA = sngValueA;
                    }
                    break;
                case 5: // 性别和中学组常模，文化程度：中学
                    if (intSex == 1) {
                        float[][] sngValueA = {
                                { 5.7f, 13.78f, 12.77f, 8.66f, 26.06f, 21.77f, 19.06f, 27.37f, 12.86f, 18.06f, 23.22f,
                                        18.63f, 34.57f, 18.96f, 26.22f, 15.12f, 20.27f, 25.14f },
                                { 2.53f, 6.83f, 4.73f, 4.76f, 5.19f, 5.58f, 4.5f, 4.42f, 4.03f, 7.98f, 10.22f, 5.41f, 7.12f,
                                        7.52f, 8.2f, 3.25f, 4.34f, 4.18f } };
                        sngStandardA = sngValueA;
                    } else {
                        float[][] sngValueA = {
                                { 5.64f, 11.92f, 12.14f, 9.95f, 28.59f, 22.83f, 18.4f, 31.71f, 12.63f, 19.1f, 22.86f,
                                        16.61f, 37.57f, 20.66f, 29.48f, 14.91f, 21.6f, 24.81f },
                                { 2.47f, 5.08f, 4.28f, 4.98f, 5f, 5.58f, 4.46f, 3.95f, 3.95f, 7.74f, 9.49f, 5.14f, 6.69f,
                                        7.36f, 7.66f, 2.87f, 3.3f, 3.19f } };
                        sngStandardA = sngValueA;
                    }
                    break;
                case 6: // 性别和大学组常模，文化程度：大学
                    if (intSex == 1) {
                        float[][] sngValueA = {
                                { 5.72f, 13.36f, 13.71f, 9.14f, 26.49f, 23f, 18.75f, 28.13f, 12.79f, 17.24f, 22.37f, 18.05f,
                                        34.32f, 18.53f, 25.7f, 16.22f, 21.36f, 25.63f },
                                { 2.48f, 6.95f, 4.39f, 4.7f, 4.23f, 4.51f, 3.91f, 2.44f, 3.56f, 7.73f, 9.92f, 4.73f, 6.1f,
                                        7.23f, 7.57f, 2.5f, 3.28f, 1.92f } };
                        sngStandardA = sngValueA;
                    } else {
                        float[][] sngValueA = {
                                { 5.61f, 10.57f, 12.8f, 9.24f, 27.39f, 22.79f, 17.77f, 32.44f, 12.57f, 17.06f, 20.72f,
                                        16.82f, 35.78f, 19.27f, 27.37f, 16.03f, 22.71f, 25.13f },
                                { 2.53f, 4.51f, 4.09f, 4.92f, 5.12f, 5.33f, 4.31f, 3.28f, 3.84f, 8.01f, 9.76f, 5.26f, 6.58f,
                                        7.19f, 7.05f, 1.91f, 1.84f, 2.44f } };
                        sngStandardA = sngValueA;
                    }
                    break;
                default: // 性别组常模
                    if (intSex == 1) {
                        float[][] sngValueA = {
                                { 5.7f, 13.68f, 13f, 8.78f, 26.16f, 22.07f, 18.98f, 27.56f, 12.84f, 17.86f, 23.01f, 18.48f,
                                        34.51f, 18.86f, 26.09f, 15.39f, 20.54f, 25.26f },
                                { 2.52f, 6.86f, 4.66f, 4.75f, 4.97f, 5.36f, 4.36f, 4.04f, 3.92f, 7.93f, 10.15f, 5.26f,
                                        6.88f, 7.45f, 8.05f, 3.12f, 4.13f, 3.76f } };
                        sngStandardA = sngValueA;
                    } else {
                        float[][] sngValueA = {
                                { 5.64f, 11.69f, 12.25f, 9.83f, 28.4f, 22.82f, 18.29f, 31.83f, 12.62f, 18.77f, 22.5f,
                                        16.64f, 37.27f, 20.43f, 29.12f, 15.1f, 21.78f, 24.86f },
                                { 2.48f, 5.02f, 4.26f, 4.98f, 5.04f, 5.54f, 4.45f, 3.86f, 3.93f, 7.82f, 9.57f, 5.16f, 6.71f,
                                        7.35f, 7.61f, 2.76f, 3.13f, 3.7f } };
                        sngStandardA = sngValueA;
                    }
                    break;
            }

            // 2行，18列的数组(2-19)
            // 标准值的得分，共18个因子，“弃权题数”和“不一致性”无标准分
            for (i = 0; i < sngStandardA[0].length; i++) {
                if (blReverse == true && i == 7) // 女性，需要反向计分
                {
                    BigDecimal bd = new BigDecimal(
                            50 + 10 * (sngStandardA[0][i] - vFactorA[i + 1][0]) / sngStandardA[1][i]);
                    vFactorA[i + 1][1] = bd.setScale(2, BigDecimal.ROUND_HALF_UP).floatValue();
                } else {
                    BigDecimal bd = new BigDecimal(
                            50 + 10 * (vFactorA[i + 1][0] - sngStandardA[0][i]) / sngStandardA[1][i]);
                    vFactorA[i + 1][1] = bd.setScale(2, BigDecimal.ROUND_HALF_UP).floatValue();
                }
            }

            // “诊断结果”
            int[] intValueA = { 70, 60 };
            String[] strValueA = { "**", "*" };
            // 注意下面的起始喝结束位置，所以特意保留VB原句供参考
            // For i = vAppraiseA.GetLowerBound(0) + 1 To
            // vAppraiseA.GetUpperBound(0) - 1
            for (i = 1; i < vAppraiseA.length - 1; i++) {
                for (j = 0; j < intValueA.length; j++) {
                    if (vFactorA[i][1] >= intValueA[j]) {
                        vAppraiseA[i] = strValueA[j];
                        break;
                    }
                }
            }

            // 20“不一致性”
            vFactorA[19][1] = 16 - vFactorA[19][0];
            vFactorA[19][0] = vFactorA[19][1];
            vAppraiseA[19] = vFactorA[19][0] > 6 ? "（回答有前后矛盾）" : "";

            // “指导意见”
            // “弃权题数”，“谎分”，“诈分”使用“原始分”，“校正分”使用“标准分”
            int[][] intValueOneA = { { 0, 5, 30, 0 }, { 2, 5, 7, 0 }, { 2, 7, 15, 22 }, { 45, 55, 69, 0 } };
            int[] intSuffixA = { 4, 4, 5, 4 };
            int[] intStyle = { 0, 0, 0, 1 };
            for (i = 0; i < intValueOneA.length; i++) {
                vDoctorIdeaA[i] = "Mmpi." + String.valueOf(i + 1) + "." + intSuffixA[i];
                for (j = 0; j < intValueOneA[1].length; j++) {
                    if (vFactorA[i][intStyle[i]] <= intValueOneA[i][j]) {
                        vDoctorIdeaA[i] = "Mmpi." + String.valueOf(i + 1) + "." + String.valueOf(j + 1);
                        break;
                    }
                }
            }

            // 顺序：5疑病、6抑郁、7癔症、8心理变态、9男性化--女性化、10偏执、11精神衰弱、12精神分裂、13轻躁症、14社会内向
            int intCount = 0; // 计数器
            for (i = 0; i < 10; i++) {
                if (vFactorA[i + 4][1] >= 60) {
                    intCount += 1;
                }
            }

            // 以标准分从大到小进行排序，相同的位置不变
            float[] sngFactorA = new float[10]; // 10个因子的标准分，可以排序
            int[] intCode = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 };
            // 注意下面的循环顺序是倒序的，所以保留VB源码供参考
            // For i = sngFactorA.GetUpperBound(0) To
            // sngFactorA.GetLowerBound(0) Step -1
            // hjw 修改了下面/**/注释掉的部分
            for (i = 0; i < sngFactorA.length - 1; i++) {
                sngFactorA[i] = vFactorA[i + 4][1];
                System.out.println("----hjw:i=" + i + ":" + sngFactorA[i]);
            }
            /*
             * for (i = sngFactorA.length - 1; i >= 0; i--) { sngFactorA[i] = vFactorA[i +
             * 4][1]; if (sngFactorA[i] >= 60) { sngFactorA[i] += (9 - i) / 100; //
             * 2006-07-19 防止分数相同 } }
             */

            // 下面这句是VB源码，功能是第一个数组按照从小到大排序，第二个数组，对应第一个的顺序同时调整位置。
            // Array.Sort(sngFactorA , intCode)
            // 下面是对应上面这句话的功能进行JAVA改写
            // Arrays.sort(intValueOneA);

            Map<Float, Integer> map = new TreeMap<Float, Integer>(new Comparator<Float>() {
                public int compare(Float obj1, Float obj2) {
                    // 降序排序
                    return obj1.compareTo(obj2);
                }
            });
            for (i = 0; i < sngFactorA.length; i++) {
                map.put(sngFactorA[i], intCode[i]);
            }
            System.out.println(map.toString());

            Set<Float> keySet = map.keySet();
            Iterator<Float> iter = keySet.iterator();
            int index = 0;
            while (iter.hasNext()) {
                Float key = iter.next();
                sngFactorA[index] = key;
                intCode[index++] = map.get(key);
                System.out.println("----hjw  key:" + key + "  index:" + (index - 1) + "  incode" + intCode[index - 1]);
            }

            switch (intCount) {
                case 1:
                    int intW = intCode[intCode.length - 1] == 0 ? 10 : intCode[intCode.length - 1];
                    vDoctorIdeaA[3 + intW] = "Mmpi.5." + String.valueOf(intW);
                    break;
                case 2:
                case 3:
                case 4:
                case 5:
                case 6:
                    String[] strCodeA = { "01", "02", "03", "04", "05", "06", "07", "08", "09", "12", "13", "14", "15",
                            "16", "17", "18", "19", "23", "24", "25", "26", "27", "28", "29", "34", "35", "36", "37", "38",
                            "39", "45", "46", "47", "48", "49", "56", "57", "58", "59", "67", "68", "69", "78", "79",
                            "89" };
                    String strCode = "";
                    if (intCode[intCode.length - 1] > intCode[intCode.length - 2]) {
                        strCode = String.valueOf(intCode[intCode.length - 2]) + String.valueOf(intCode[intCode.length - 1]);
                    } else {
                        strCode = String.valueOf(intCode[intCode.length - 1]) + String.valueOf(intCode[intCode.length - 2]);
                    }
                    for (i = 0; i < strCodeA.length; i++) {
                        if (strCode.equals(strCodeA[i])) {
                            vDoctorIdeaA[19] = "Mmpi.6." + String.valueOf(i + 1);
                            break;
                        }
                    }
                    break;
                case 7:
                case 8:
                case 9:
                case 10:
                    vDoctorIdeaA[19] = "Mmpi.5.16";
                    break;
                default:
                    break;
            }

            // 由于原先条件有误，现需要修改
            // 在2-6个时，将2个以后的因子内容显示；
            // 在大于6个时，全部显示
            // hjw:删除以下部分，在上面部分增加因子赋值了
            int intLocal = -1;
            if (intCount > 6) {
                intLocal = 0;
            } else if (intCount > 2) {
                intLocal = 2;
            }
            if (intLocal >= 0) {
                int intCalc = 0;
                int intNum;
                for (i = intCode.length - 1; i >= 0; i--) {
                    intCalc += 1;
                    if (intCalc > (intCount - intLocal)) {
                        break;
                    }
                    intNum = intCode[i] == 0 ? 13 : intCode[i] + 3;
                    vDoctorIdeaA[intNum] = "Mmpi.5." + String.valueOf(intNum - 3);
                }
            }

            // 566中多出的因子，号从11开始排
            // 15外显性焦虑，16依赖性，17支配性，18社会责任，19控制力
            for (i = 0; i < 4; i++) {
                if (vFactorA[i + 14][1] >= 60) {
                    vDoctorIdeaA[i + 14] = "Mmpi.5." + String.valueOf(i + 11);
                }
            }

            // 将399中多余内容清空
            if (int399or566 == 1) {
                for (i = 14; i < 19; i++) // 15-19的因子内容
                {
                    vFactorA[i][0] = 0;
                    vFactorA[i][1] = 0;
                    vAppraiseA[i] = "";
                    vDoctorIdeaA[i] = "";
                }
            }

            ClsScore.Mmpi mmpi = new ClsScore.Mmpi();
            mmpi.setDrop_o(vFactorA[0][0]);
            mmpi.setDrop_d(vDoctorIdeaA[0]);

            mmpi.setLie_o(vFactorA[1][0]);
            mmpi.setLie_s(vFactorA[1][1]);
            mmpi.setLie_a(vAppraiseA[1]);
            mmpi.setLie_d(vDoctorIdeaA[1]);

            mmpi.setInfra_o(vFactorA[2][0]);
            mmpi.setInfra_s(vFactorA[2][1]);
            mmpi.setInfra_a(vAppraiseA[2]);
            mmpi.setInfra_d(vDoctorIdeaA[2]);

            mmpi.setDefen_o(vFactorA[3][0]);
            mmpi.setDefen_s(vFactorA[3][1]);
            mmpi.setDefen_a(vAppraiseA[3]);
            mmpi.setDefen_d(vDoctorIdeaA[3]);

            mmpi.setHypoch_o(vFactorA[4][0]);
            mmpi.setHypoch_s(vFactorA[4][1]);
            mmpi.setHypoch_a(vAppraiseA[4]);
            mmpi.setHypoch_d(vDoctorIdeaA[4]);

            mmpi.setDepre_o(vFactorA[5][0]);
            mmpi.setDepre_s(vFactorA[5][1]);
            mmpi.setDepre_a(vAppraiseA[5]);
            mmpi.setDepre_d(vDoctorIdeaA[5]);

            mmpi.setHyste_o(vFactorA[6][0]);
            mmpi.setHyste_s(vFactorA[6][1]);
            mmpi.setHyste_a(vAppraiseA[6]);
            mmpi.setHyste_d(vDoctorIdeaA[6]);

            mmpi.setPsychop_o(vFactorA[7][0]);
            mmpi.setPsychop_s(vFactorA[7][1]);
            mmpi.setPsychop_a(vAppraiseA[7]);
            mmpi.setPsychop_d(vDoctorIdeaA[7]);

            mmpi.setMascu_o(vFactorA[8][0]);
            mmpi.setMascu_s(vFactorA[8][1]);
            mmpi.setMascu_a(vAppraiseA[8]);
            mmpi.setMascu_d(vDoctorIdeaA[8]);

            mmpi.setPara_o(vFactorA[9][0]);
            mmpi.setPara_s(vFactorA[9][1]);
            mmpi.setPara_a(vAppraiseA[9]);
            mmpi.setPara_d(vDoctorIdeaA[9]);

            mmpi.setPsychas_o(vFactorA[10][0]);
            mmpi.setPsychas_s(vFactorA[10][1]);
            mmpi.setPsychas_a(vAppraiseA[10]);
            mmpi.setPsychas_d(vDoctorIdeaA[10]);

            mmpi.setSchi_o(vFactorA[11][0]);
            mmpi.setSchi_s(vFactorA[11][1]);
            mmpi.setSchi_a(vAppraiseA[11]);
            mmpi.setSchi_d(vDoctorIdeaA[11]);

            mmpi.setHypoma_o(vFactorA[12][0]);
            mmpi.setHypoma_s(vFactorA[12][1]);
            mmpi.setHypoma_a(vAppraiseA[12]);
            mmpi.setHypoma_d(vDoctorIdeaA[12]);

            mmpi.setSocial_o(vFactorA[13][0]);
            mmpi.setSocial_s(vFactorA[13][1]);
            mmpi.setSocial_a(vAppraiseA[13]);
            mmpi.setSocial_d(vDoctorIdeaA[13]);

            mmpi.setTotalResult_d(vDoctorIdeaA[19]);

            mmpi.setMani_o(vFactorA[14][0]);
            mmpi.setMani_s(vFactorA[14][1]);
            mmpi.setMani_a(vAppraiseA[14]);
            mmpi.setMani_d(vDoctorIdeaA[14]);

            mmpi.setDepend_o(vFactorA[15][0]);
            mmpi.setDepend_s(vFactorA[15][1]);
            mmpi.setDepend_a(vAppraiseA[15]);
            mmpi.setDepend_d(vDoctorIdeaA[15]);

            mmpi.setDomi_o(vFactorA[16][0]);
            mmpi.setDomi_s(vFactorA[16][1]);
            mmpi.setDomi_a(vAppraiseA[16]);
            mmpi.setDomi_d(vDoctorIdeaA[16]);

            mmpi.setRespon_o(vFactorA[17][0]);
            mmpi.setRespon_s(vFactorA[17][1]);
            mmpi.setRespon_a(vAppraiseA[17]);
            mmpi.setRespon_d(vDoctorIdeaA[17]);

            mmpi.setControl_o(vFactorA[18][0]);
            mmpi.setControl_s(vFactorA[18][1]);
            mmpi.setControl_a(vAppraiseA[18]);
            mmpi.setControl_d(vDoctorIdeaA[18]);

            mmpi.setDiffer_o(vFactorA[19][0]);
            mmpi.setDiffer_a(vAppraiseA[19]);

            result.setObject(mmpi);
            return result;
        } catch (ArithmeticException e) {
            result.setMessage(e.toString());
            return result;
        }
    }

    // 五、六、明尼苏达多相人格测验mmpi399,mmpi566 ☆
    // “重点提示”（分性别，这里分性别不是很确定指的是上一阶段计算得分的分性别还是报告分性别，看下来报告是不分性别的）
    private String[] GetMmpiReport(Map map) {
        // 下面因子名称字段改成.toLowerCase()小写，是因为JAVA转json的时候会把大写字母转成小写字母
        // 第一个，错误信息；第二个，量表得分部分；第三个，量表指导意见_d数组部分
        // String[] strResult = {"","",""};
        String[] strResult = { "", "", "", "", "" };
        try {
            int i = 0;
            String[] gcName1 = "谎　分,诈　分,校正分".split(",");
            String[] gdName1 = "L,F,K".split(",");
            String[] geName1 = "Lie,Infra,Defen".toLowerCase().split(",");

            int[] strIntA = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 };
            String[] gcName2 = "疑　病,抑　郁,癔　症,心理变态,男性化-女性化,偏　执,精神衰弱,精神分裂,轻躁症,社会内向".split(",");
            String[] gdName2 = "Hs,D,Hy,Pd,Mf,Pa,Pt,Sc,Ma,Si".split(",");
            String[] geName2 = "Hypoch,Depre,Hyste,Psychop,Mascu,Para,Psychas,Schi,Hypoma,Social".toLowerCase()
                    .split(",");

            String[] gcName3 = "外显性焦虑,依赖性,支配性,社会责任,控制力".split(",");
            String[] gdName3 = "Mas,Dy,Do,Re,Cn".split(",");
            String[] geName3 = "Mani,Depend,Domi,Respon,Control".toLowerCase().split(",");

            String[] gvName1 = {};
            String[] gvName2 = {};
            String[] gvName3 = {};

            switch (g_CorE) {
                case 1: // chinese
                    gvName1 = gcName1;
                    gvName2 = gcName2;
                    gvName3 = gcName3;
                    break;
                case 2: // english
                    gvName1 = gdName1;
                    gvName2 = gdName2;
                    gvName3 = gdName3;
                    break;
            }

            int intCount = 0; // 计数，计有几个因子是有评价的
            if (g_inblFactor) // 因子得分
            {
                strResult[1] += "<table cellpadding='0' cellspacing='0' width='100%' border='0'>";

                strResult[1] += "<tr><td" + subTitle(1, tWidth) + ">编号</td><td" + subTitle(0, oWidth * 3)
                        + ">指标</td><td" + subTitle(1, tWidth) + ">原始分</td>" + "<td" + subTitle(1, tWidth)
                        + ">标准分</td><td" + subTitle(1, tWidth) + ">参考提示</td></tr>";

                for (i = 0; i < gcName1.length; i++) {
                    strResult[1] += "<tr><td></td><td" + subTitle(0, -1) + ">" + gvName1[i] + "</td><td"
                            + subValue(1, -1) + ">" + map.get(geName1[i] + "_o") + "</td>" + "<td" + subValue(1, -1)
                            + ">" + map.get(geName1[i] + "_s") + "</td><td" + subValue(1, -1) + ">"
                            + map.get(geName1[i] + "_a") + "</td></tr>";
                }

                for (i = 0; i < gcName2.length; i++) {
                    strResult[1] += "<tr><td" + subTitle(1, -1) + ">" + strIntA[i] + "</td><td" + subTitle(0, -1) + ">"
                            + gvName2[i] + "</td>" + "<td" + subValue(1, -1) + ">" + map.get(geName2[i] + "_o")
                            + "</td><td" + subValue(1, -1) + ">" + map.get(geName2[i] + "_s") + "</td>" + "<td"
                            + subValue(1, -1) + ">" + map.get(geName2[i] + "_a") + "</td></tr>";
                    if (String.valueOf(map.get(geName2[i] + "_d")).length() > 0) {
                        intCount += 1;
                    }
                }

                // 如果是566则有下面的部分
                if (Float.valueOf(String.valueOf(map.get("Mani_o".toLowerCase()))) > 0
                        || Float.valueOf(String.valueOf(map.get("Depend_o".toLowerCase()))) > 0
                        || Float.valueOf(String.valueOf(map.get("Domi_o".toLowerCase()))) > 0
                        || Float.valueOf(String.valueOf(map.get("Respon_o".toLowerCase()))) > 0
                        || Float.valueOf(String.valueOf(map.get("Control_o".toLowerCase()))) > 0) {
                    for (i = 0; i < gcName3.length; i++) {
                        strResult[1] += "<tr><td></td><td" + subTitle(0, -1) + ">" + gvName3[i] + "</td><td"
                                + subValue(1, -1) + ">" + map.get(geName3[i] + "_o") + "</td>" + "<td" + subValue(1, -1)
                                + ">" + map.get(geName3[i] + "_s") + "</td><td" + subValue(1, -1) + ">"
                                + map.get(geName3[i] + "_a") + "</td></tr>";
                    }
                }

                // 不一致性
                strResult[1] += "<tr><td></td>" + "<td" + subTitle(0, -1) + ">不一致性</td>" + "<td" + subValue(1, -1) + ">"
                        + map.get("Differ_o".toLowerCase()) + "</td>" + "<td colspan='3'" + subValue(1, -1) + ">"
                        + map.get("Differ_a".toLowerCase()) + "</td></tr>";
                // 说明
                strResult[1] += "<tr><td colspan='2'" + subTitle(1, -1) + ">注：*(T分大于一个标准差)</td>" + "<td colspan='2'"
                        + subTitle(1, -1) + ">**(T分大于二个标准差)</td>" + "<td" + subValue(1, -1) + ">弃权数："
                        + map.get("Drop_o".toLowerCase()) + "</td></tr>";

                strResult[1] += "</table>";
            }

            // 按5.0的排序方式进行修改
            // 如果有，就显示
            String strCode = "";
            // 以下两行不确定最后一个单词的大小写
//             String[] strItemA = {"drop", "lie", "infra", "defen", "totalresult"};
            String[] strItemA = { "drop", "lie", "infra", "defen", "totalResult" };
            for (i = 0; i < strItemA.length; i++) {
                if (map.get(strItemA[i] + "_d").toString().length() > 0) {
                    strCode += map.get(strItemA[i] + "_d") + "|";
                }
            }

            // 是>=60分，在2-6个时，将2个以后的因子内容显示；
            // 在大于6个时，全部显示
            String[] strSubItemA = { "Hypoch", "Depre", "Hyste", "Psychop", "Mascu", "Para", "Psychas", "Schi",
                    "Hypoma", "Social" };
            if (intCount > 0) {
                float[] sngScoreA = new float[intCount];
                String[] strCodeA = new String[intCount];
                intCount = 0;
                for (i = 0; i < strSubItemA.length; i++) {
                    if (map.get(strSubItemA[i].toLowerCase() + "_d").toString().length() > 0) {
                        // 下面这句除法一会儿检查下
                        sngScoreA[intCount] = Float
                                .valueOf(String.valueOf(map.get(strSubItemA[i].toLowerCase() + "_s")));
                        strCodeA[intCount] = map.get(strSubItemA[i].toLowerCase() + "_d").toString();
                        intCount += 1;
                    }
                }

                // Array.Sort(sngScoreA, strCodeA)

                // 下面这句是VB源码，功能是第一个数组按照从小到大排序，第二个数组，对应第一个的顺序同时调整位置。
                // Array.Sort(sngScoreA , strCodeA)
                // 下面是对应上面这句话的功能进行JAVA改写
                // Arrays.sort(intValueOneA);

                Map<Float, String> mapTemp = new TreeMap<Float, String>(new Comparator<Float>() {
                    public int compare(Float obj1, Float obj2) {
                        // 降序排序
                        return obj1.compareTo(obj2);
                    }
                });
                for (i = 0; i < sngScoreA.length; i++) {
                    mapTemp.put(sngScoreA[i], strCodeA[i]);
                    // System.out.println(sngScoreA[i] + ":" + strCodeA[i]);
                }

                Set<Float> keySet = mapTemp.keySet();
                Iterator<Float> iter = keySet.iterator();
                int index = 0;
                while (iter.hasNext()) {
                    Float key = iter.next();
                    sngScoreA[index] = key;
                    strCodeA[index++] = mapTemp.get(key);
                }

                // 从大到小
                for (i = 0; i < sngScoreA.length; i++) {
                    strCode += strCodeA[i] + "|";
                }
            }

            // 附加的内容
            String[] strAddItemA = { "Mani", "Depend", "Domi", "Respon", "Control" };
            for (i = 0; i < strAddItemA.length; i++) {
                if (map.get(strAddItemA[i].toLowerCase() + "_d").toString().length() > 0) {
                    strCode += map.get(strAddItemA[i].toLowerCase() + "_d") + "|";
                }
            }

            // 医生意见
            if (strCode.length() > 0) {
                strCode = strCode.substring(0, strCode.length() - 1);
            }

            strResult[2] = strCode;

            // 预警
            for (i = 0; i < gcName1.length; i++) {
                if (map.get(geName1[i] + "_a").equals("*") || map.get(geName1[i] + "_a").equals("**")) {
                    strResult[3] = "*";
                    strResult[4] += gcName1[i].toString() + "异常，";
                }
            }

            for (i = 0; i < gcName2.length; i++) {
                if (map.get(geName2[i] + "_a").equals("*") || map.get(geName2[i] + "_a").equals("**")) {
                    strResult[3] = "*";
                    strResult[4] += gcName2[i].toString() + "异常，";
                }
            }

            // 如果是566则有下面的部分
            if (Float.valueOf(String.valueOf(map.get("Mani_o".toLowerCase()))) > 0
                    || Float.valueOf(String.valueOf(map.get("Depend_o".toLowerCase()))) > 0
                    || Float.valueOf(String.valueOf(map.get("Domi_o".toLowerCase()))) > 0
                    || Float.valueOf(String.valueOf(map.get("Respon_o".toLowerCase()))) > 0
                    || Float.valueOf(String.valueOf(map.get("Control_o".toLowerCase()))) > 0) {
                for (i = 0; i < gcName3.length; i++) {
                    if (map.get(geName3[i] + "_a").equals("*") || map.get(geName3[i] + "_a").equals("**")) {
                        strResult[3] = "*";
                        strResult[4] += gcName3[i].toString() + "异常，";
                    }
                }
            }

            if (map.get("Differ_a".toLowerCase()).equals("（回答有前后矛盾）")) {
                strResult[3] = "*";
                strResult[4] += "不一致性（回答有前后矛盾），";
            }

            if (strResult[4].length() > 0) {
                strResult[4] = strResult[4].substring(0, strResult[4].length() - 1);
            } else {
                strResult[3] = "0";
                strResult[4] += "正常";
            }

            return strResult;
        } catch (ArithmeticException e) {
            strResult[0] = "失败";
            return strResult;
        }
    }


}
